package com.luotat.productclient.controller;

import com.luotat.pojo.result.Result;
import com.luotat.productclient.client.ProductServiceImpl;
import com.luotat.pojo.product.Product;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@AllArgsConstructor
@RestController
@Slf4j
@RequestMapping("/product")
public class ProductServiceClientController
{
    private final ProductServiceImpl productService;

    /**
     * 添加商品
     */
    @PostMapping
    public Result insert(@RequestBody Product product)
    {
        log.info("In client insert");
        return productService.insert(product);
    }

    /**
     * 删除商品
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id)
    {
        log.info("In client delete");
        return productService.delete(id);
    }

    // 修改商品
    @PutMapping
    public Result update(@RequestBody Product product)
    {
        log.info("In client update");
        return productService.update(product);
    }

    /**
     * 根据id查询商品
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") Integer id)
    {
        log.info("In client getById");
        return productService.getById(id);
    }

    /**
     * 查询所有商品
     */
    @GetMapping("/getAll")
    public Result getAll()
    {
        log.info("In client getAll");
        return productService.getAll();
    }
}